﻿@{
    ViewBag.Title = "职员列表";
}
<script type="text/javascript">

    var LastSelectID = 0; //最后一次选中的行ID
    var jqGridHeight_Permission_Organize_DutyDetails = 0;
    $(document).ready(function () {
        //alert($("#mainContent_permission_organize_index").height());
        //$("#mainContent_Permission_Organize_DutyDetails").height($("#mainContent_permission_organize_index").height());
        
        jqGridHeight_Permission_Organize_DutyDetails = $("#mainContent_permission_organize_index").height();
        $("#mainContent_Permission_Organize_DutyDetails").height(jqGridHeight_Permission_Organize_DutyDetails-30);
        GridGet_DutyDetails();
    });

    function GridGet_DutyDetails() {
        $("#List_Permission_Organize_DutyDetails").jqGrid({
            url: "/Permission/Organize/StuffList",
            datatype: "json",
            mtype: "post",
            colNames: ['Id', '用户名', '编号', '姓名', '描述'],
            colModel: [
                        { label: 'Id', name: 'Id', index: 'Id', width: 5, align: "center", sortable: false, hidden: true },
                        { label: '用户名', name: 'UserName', index: 'UserName', width: 120, align: "center", sortable: false },
                        { label: '编号', name: 'Code', index: 'Code', width: 100, align: "center", sortable: false },
                        { label: '姓名', name: 'RealName', index: 'RealName', width: 100, align: "center", sortable: false },
                        { label: '描述', name: 'Description', index: 'Description', width: 130, align: "center", sortable: false }
                       ],
            beforeRequest: function (d) {
                $(this).jqGrid('setGridParam', { postData: { "DutyId": "@ViewBag.DutyId", "keyword": $("#keyword__Permission_Organize_DutyDetails").val()} });
            },
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_List_Permission_Organize_DutyDetails");
                ajaxbg.hide();
            },
            onSelectRow: User_GetStuffList,
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            height: jqGridHeight_Permission_Organize_DutyDetails - 60
        }).navGrid('#pager_Permission_Organize_DutyDetails', { edit: false, add: false, del: false, refresh: false, search: false });
    }
    //选中某一行，获得行
    function User_GetStuffList() {
        var GridObj_DutyDetails = $("#List_Permission_Organize_DutyDetails");
        var staffId = GridObj_DutyDetails.jqGrid("getGridParam", "selrow");

        if (staffId != "") {
            $("#editStuff_permission_organize_index").show();
            $("updatepic_permission_organize_index").show();
            isStaff = true; //表明已选择了职员
            $("#del_permission_organize_index").show(); //选择职员，有删除按钮

            //由选择的行号获取对应记录的id

            var tempId = GridObj_DutyDetails.getCell(parseInt(staffId), "Id").toString();

            $("#editStuff_permission_organize_index").show();
            $("#updatepic_permission_organize_index").show();
            var editStuffUrl_permission_organize_index = "/Permission/organize/EditStaff/" + tempId;
            var updatepicUrl_permission_organize_index = "/Permission/organize/UpdatePic/" + tempId;
            $("#editStuff_permission_organize_index").attr("href", editStuffUrl_permission_organize_index);
            $("#updatepic_permission_organize_index").attr("href", updatepicUrl_permission_organize_index);
        } else {
            $("#editStuff_permission_organize_index").hide();
            $("#updatepic_permission_organize_index").hide();
            $("#del_permission_organize_index").hide(); //没有选择职员，就没有删除按钮
        }
        deleteID_permission_organize_index = tempId;
    }
    //按条件查询
    $("#keyword__Permission_Organize_DutyDetails").keyup(function () {
        $("#List_Permission_Organize_DutyDetails").trigger("reloadGrid"); //重新加载JqGrid;
    });
    function CreatStaffAdded_Permission_Organize(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点       
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            if (json.callbackType == "Create") {
                //添加成功
                alertMsg.correct("新增成功！");
                $.pdialog.closeCurrent();
            } else if (json.callbackType == "Edit") {
                //更新成功
                alertMsg.correct("更新成功！");
                $("#editStuff_permission_organize_index").attr("href", href_permission_organize_index + "/EditStaff/{sid_user}").hide();
                deleteID_permission_organize_index = 0;
                $.pdialog.closeCurrent();
            }
            $("#List_Permission_Organize_DutyDetails").trigger("reloadGrid");
        }
        else {
            //alertMsg.error("操作失败,请稍后再试！"); 
        }
        $("#background,#progressBar,#lui_List_Permission_Organize_DutyDetails").hide();
    }
</script>
<div class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            <li>关键字：<input type="text" id="keyword__Permission_Organize_DutyDetails" /></li>
        </ul>
    </div>
    <div id="mainContent_Permission_Organize_DutyDetails">
        <div class="tableList" layouth="60">
            <table id="List_Permission_Organize_DutyDetails">
            </table>
            <div id="pager_Permission_Organize_DutyDetails">
            </div>
        </div>
    </div>
</div>
